﻿CREATE FUNCTION [maint].[GetDeviceListExpression]
(
	@DeviceName sysname, 
	@DeviceDoP int
)
RETURNS nvarchar(max)
AS
BEGIN

	DECLARE @DeviceListExpr nvarchar(max) = N'', @ParallelDeviceNo int = 1;
	WHILE(@ParallelDeviceNo <= @DeviceDoP)
	BEGIN
		SET @DeviceListExpr = @DeviceListExpr + N'[' + @DeviceName + N'.' + CAST(@ParallelDeviceNo AS nvarchar) + N'],'
		SET @ParallelDeviceNo = @ParallelDeviceNo + 1;
	END
	SET	@DeviceListExpr = LEFT(@DeviceListExpr,LEN(@DeviceListExpr)-1);

	RETURN @DeviceListExpr;
END